import {
  DialogPlugin,
  LoadingPlugin,
  MessagePlugin,
  NotifyPlugin,
} from "tdesign-vue-next";
let loadingInstance;

export default {
  // 消息提示
  msg(content) {
    MessagePlugin.info(content);
  },
  // 错误消息
  msgError(content) {
    MessagePlugin.error(content);
  },
  // 成功消息
  msgSuccess(content) {
    MessagePlugin.success(content);
  },
  // 警告消息
  msgWarning(content) {
    MessagePlugin.warning(content);
  },
  // 弹出提示
  alert(content) {
    const alertDia = DialogPlugin.alert({
      header: "系统提示",
      body: content,
      onConfirm: () => {
        alertDia.hide();
      },
    });
  },
  // 错误提示
  alertError(content) {
    const alertDia = DialogPlugin.alert({
      header: "系统提示",
      body: content,
      theme: "danger",
      onConfirm: () => {
        alertDia.hide();
      },
    });
  },
  // 成功提示
  alertSuccess(content) {
    const alertDia = DialogPlugin.alert({
      header: "系统提示",
      body: content,
      theme: "success",
      onConfirm: () => {
        alertDia.hide();
      },
    });
  },
  // 警告提示
  alertWarning(content) {
    const alertDia = DialogPlugin.alert({
      header: "系统提示",
      body: content,
      theme: "warning",
      onConfirm: () => {
        alertDia.hide();
      },
    });
  },
  // 通知提示
  notify(content) {
    NotifyPlugin.info(content);
  },
  // 错误通知
  notifyError(content) {
    NotifyPlugin.error(content);
  },
  // 成功通知
  notifySuccess(content) {
    NotifyPlugin.success(content);
  },
  // 警告通知
  notifyWarning(content) {
    NotifyPlugin.warning(content);
  },
  // 确认窗体
  confirm(content) {
    return new Promise((resolve, reject) => {
      const confirmDia = DialogPlugin.confirm({
        header: "系统提示",
        body: content,
        confirmBtn: "确定",
        cancelBtn: "取消",
        theme: "warning",
        onConfirm: () => {
          resolve(true);
          confirmDia.destroy();
        },
        onClose: () => {
          reject(false);
          confirmDia.hide();
        },
      });
    });
  },

  // 提交内容
  prompt(content) {
    return new Promise((resolve, reject) => {
      const confirmDia = DialogPlugin.confirm({
        header: "系统提示",
        body: "TDesign 没有这个插件, 请自行实现",
        confirmBtn: "确定",
        cancelBtn: "取消",
        theme: "warning",
        onConfirm: () => {
          resolve(true);
          confirmDia.destroy();
        },
        onClose: () => {
          reject(false);
          confirmDia.hide();
        },
      });
    });
  },
  // 打开遮罩层
  loading(content) {
    loadingInstance = LoadingPlugin({
      delay: 0,
      attach: "body",
      text: content,
      loading: true,
      fullscreen: true,
    });
  },
  // 关闭遮罩层
  closeLoading() {
    loadingInstance.hide();
  },
};
